import EventEmitter from 'eventemitter2';
import { Room } from '../api/Room';
import { CardEvent } from '../api/CardEvent';

export const events = new EventEmitter();

// 部门抽牌事件
events.on('turnStart', (room: Room, deptId: string) => {
	const card = room.pools.draw(deptId, true);
	if (card) CardEvent.addCard(room, deptId, card);
});

// 恢复行动事件
events.on('turnStart', (room: Room, deptId: string) => {
	const dept = room.getDept(deptId);
	if (!dept) return;
	if (dept.pointMax < 10) dept.pointMax++;
	dept.point = dept.pointMax;
});

// 回合开始事件
events.on('turnStart', (room: Room, deptId: string) => {
	const dept = room.getDept(deptId);
	if (!dept) return;
	Object.values(dept.fieldCards).forEach((card) => {
		card.turnStart(room, deptId);
	});
});

// 回合结束事件
events.on('turnEnd', (room: Room, deptId: string) => {
	const dept = room.getDept(deptId);
	if (!dept) return;
	Object.values(dept.fieldCards).forEach((card) => {
		card.turnEnd(room, deptId);
	});
});

// 游戏开始
events.on('gameStart', (room: Room) => {
	// Object.values(room.depts).forEach((dept) => {
	// 	CardEvent.drawCard(room, dept.deptId, dept.deptId, 30, true);
	// });
	room.isStartGame = true;
});
